<?php

namespace App\Http\Requests\Role;

use App\Http\Requests\ApiRequest;

class UpdateRequest extends ApiRequest
{
    /**
     * 'permission/role_manage/RoleDataAdd/id'：前端路由
     *
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        if(is_bool(self::checkPermission('permission/role_manage/RoleDataAdd/id'))){
            return self::checkPermission('permission/role_manage/RoleDataAdd/id');
        }else{
            return false;
        }
    }


    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'id' => 'required|integer',
            'name' => 'required|string',
            'description' => 'required|string',
            'permission_ids' => 'array',
        ];
    }

    public function messages()
    {
        return [
            'id.required' => '缺少ID',
            'id.integer' => 'ID必须为整数',
            'name.required'=>'请输入角色名称',
            'name.string'=>'角色名称必须为字符类型',
            'description.required' => '请填写角色描述',
            'description.string' => '角色描述必须为字符类型',
            'permission_ids.array' => '权限ID必须为数组',
        ];
    }
}
